package haiyangwangwork.day10.第一组.杨琳;

import java.util.Scanner;

public class Demo2 {
    //有一个数组{12,23,34,45,56,67,78,89}，要求用户输入一个数字，判断该数字是否在数组中。如果
    //在，删除掉它，但不能更改原有顺序。注意：删除它，那么数组长度要-1；
    public static void main(String[] args) {
        int[] array = new int[]{12, 23, 34, 45, 56, 67, 78, 89};
        Scanner input = new Scanner(System.in);
        System.out.println("请输入一个数");
        int num = input.nextInt();
        int[] newArray = new int[array.length - 1];
        int sign = -2;
        for (int i = 0; i < array.length; i++) {
            if (num == array[i]) {
                sign = i;
                break;
            }else {
                System.out.println("该数字没有在这个数组中");
                break;
            }
        }
        if (sign != -2) {
            for (int j = 0;j < array.length;j++){
                if(j < sign){
                    newArray[j]=array[j];
                }else if(j == sign){
                    continue;
                }else if (j > sign){
                    newArray[j-1]=array[j];
                }
            }
            array=newArray;
            System.out.println("新数组为：");
            for (int i = 0;i < array.length;i++){

                System.out.print(array[i]+" ");
            }
        }
    }


}
